package com.hxq.library.controller;

import com.hxq.library.service.IUserService;
import com.hxq.library.service.Impl.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @Author: Ljx
 * @Date: 2021/11/25 19:14
 * @role:
 */
@WebServlet("/forgetPassword")
public class ForgetPasswordServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html,utf-8");
        HttpSession session = req.getSession();
        String studentId = req.getParameter("studentId");
        IUserService service = new UserService();
        try {
            boolean selectUser = service.selectUser(studentId);
            if (selectUser){
                session.setAttribute("account1", studentId);
                resp.sendRedirect(req.getContextPath()+"inputNum.jsp");
            }else {
                req.setAttribute("msg3","该用户不存在，请重新输入！！！");
                req.getRequestDispatcher("forgetPassword.jsp").forward(req,resp);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
